package suzf.top.base.rx

import rx.Observable
import rx.functions.Func1
import suzf.top.base.common.ResultCode
import suzf.top.base.data.protocol.BaseResp

/**
 *
 *========================
 * Created with AndroidStudio
 * Author:Mr.Su
 * Date:2019-09-09
 * Time:13:01
 * ========================
 */
/*
    通用数据类型转换封装
 */
class BaseFunc<T>: Func1<BaseResp<T>, Observable<T>> {
    override fun call(t: BaseResp<T>): Observable<T> {
        if (t.status != ResultCode.SUCCESS){
            return Observable.error(BaseException(t.status,t.message))
        }

        return Observable.just(t.data)
    }
}
